<template>
    <div>
        <div class="header" style="background-color: white">
            <el-page-header @back="goBack" content="团队管理">
            </el-page-header>
        </div>
        <el-divider></el-divider>
        <div v-show="ad==1">
            <el-form :model="hrteam" label-width="100px">
                <el-container>
                    <el-form-item label="团队名称：">
                        <el-input v-model="hrteam.teamName" size="small" placeholder="团队名称" style="width: 150px"></el-input>
                    </el-form-item>
                        <el-form-item label="团队成员：">
                            <el-input v-model="hrteam.teamMember"  size="small" placeholder="团队成员" style="width: 150px"></el-input>
                        </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="Hrteamsag" size="small" >查询</el-button>
                        <el-button @click="HrteamAdd" size="small" >添加团队</el-button>
                    </el-form-item>
                </el-container>
            </el-form>
            <el-table :data="hrteams.slice((currentPage-1)*pagesize,currentPage*pagesize)" height="500" border style="width: 100%">
                <el-table-column label="团队名称" prop="teamName"></el-table-column>
                <el-table-column label="负责人" prop="teamPrincipal"></el-table-column>
                <el-table-column label="负责员工" prop="teamMember"> </el-table-column>
                <el-table-column label="团队介绍" prop="teamIntro"> </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-dropdown>
                            <el-button type="primary" size="small" >
                                操作<i class="el-icon-arrow-down el-icon--right"></i>
                            </el-button>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item @click.native="HrteamsagById(scope)">详情</el-dropdown-item>
                                <el-dropdown-item @click.native="HrteamById(scope)">修改</el-dropdown-item>
                                <el-dropdown-item @click.native="DelHrteam(scope)">删除</el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="[5, 10, 20, 40]"
                    :page-size="pagesize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="hrteams.length">
            </el-pagination>
        </div>
        <hrteall :hrteamall="Byid" :tue="tue" @coles="coles" @AddHrTeam="AddHrTeam" v-if="ad==2"></hrteall>
    </div>
</template>

<script>
    import hrteall from "../../gsl/HrTeam/HrTeamAll"
    import hrteam from "../../../model/gsl/HrTeam/hrteam";
    const hrt=hrteam.getInstance();
    export default {
        components: {hrteall},
        data() {
            return {
                ad: 1,
                currentPage: 1, //初始页
                pagesize: 10,    //    每页的数
                hrteams: [],
                hrteam: {},//高级查询的数据
                Byid: {},//根据id查询的数据
                tue: false,
            };
        },
        created() {
            this.Hrteamsag();
        },
        methods: {
            // 初始页currentPage、初始每页数据数pagesize和数据data
            handleSizeChange: function (size) {
                this.pagesize = size;
                console.log(this.pagesize)  //每页下拉显示数据
            },
            handleCurrentChange: function (currentPage) {
                this.currentPage = currentPage;
                console.log(this.currentPage)  //点击第几页
            },
            Hrteamsag() {
                hrt.list(this.hrteam).then((re) => {
                    this.hrteams = re.data.data;
                    this.hrteam = {}
                })
            },coles(s){
                this.ad=s;
            },
            HrteamAdd(){
                this.ad=2;
                this.Byid = {};
                this.tue=false;
            },
            HrteamById(ss){
                hrt.listByid(ss.row.id).then((re) => {
                    this.Byid = {};
                    this.Byid=re.data.data;
                    this.tue=false;
                    this.ad=2;
                })
            },
            HrteamsagById(ss){
                hrt.listByid(ss.row.id).then((re) => {
                    this.Byid = {};
                    this.Byid=re.data.data;
                    this.tue=true;
                    this.ad=2;
                })
            },
            DelHrteam(ss){
                hrt.remove(ss.row.id).then((re) => {
                    if (re.data.data==1) {
                        this.$message.success({
                            message:'删除成功',
                            duration:1000
                        })
                        this.Hrteamsag();
                        this.ad=1;
                    }else {
                        alert("删除失败！")
                        this.ad=2;
                    }
                })
            },
            AddHrTeam(hr){
                if (hr.id) {
                    hrt.update(hr).then((re)=>{
                        if (re.data.data==1) {
                            this.$message.success({
                                message:'修改成功',
                                duration:1000
                            })
                            this.Hrteamsag();
                            this.ad=1;
                        }else {
                            alert("修改失败！")
                            this.ad=2;
                        }
                    })
                }else {
                    hrt.save(hr).then((re)=>{
                        if (re.data.data==1) {
                            this.$message.success({
                            message:'添加成功',
                            duration:1000
                        })
                            this.Hrteamsag();
                            this.ad=1;
                        }else {
                            alert("添加失败！")
                            this.ad=2;
                        }
                    })
                }
            },
            goBack(){
                history.back()
            }
        }
    }
</script>

<style scoped>

</style>
